<template>
  <div>
    <!-- 上传的报告预览 -->
    <PreviewFileContent
      v-if="previewFileShow"
      :file="filepreview"
    ></PreviewFileContent>

    <!-- 生成的报告预览 -->
    <div v-if="previewDialogVisible" v-html="reportHtml"></div>
  </div>
</template>
<script>
// import PreviewFile from "@/ModuleEntrust/components/EntrustManage/PreviewFile.vue";
// import ModuleEntrust from "panna-module-entrust";
import {
  Get,
  ReportVerifyReject,
  ReportVerifyPass,
} from "./api/Report/ReportManage.js";
export default {
  name: "AuditReportStandingBookAuditDetails",
  // components: { PreviewFile: ModuleEntrust.PreviewFile },
  props: {
    fromSource: {
      type: String, // 数组 // 对象或数组默认值必须从一个工厂函数获取
      default: "",
    },
    row: {
      type: Object,
      default: () => { },
    },
    reportData: {
      type: Object,
      default: () => { },
    },
  },
  data() {
    return {
      reportHtml: "",
      filepreview: {
        fileName: "",
        url: "",
        storageFileName: "",
      },
      previewFileShow: false,
      previewDialogVisible: false,
    };
  },
  watch: {},
  created() {
    if (this.fromSource === "verify") {
      this.innerGetReportList(this.row);
    } else {
      this.previewReport(this.reportData);
    }
  },
  methods: {
    innerGetReportList(row) {
      this.nextOrPrev = false;
      Get({ id: row.auditDataId })
        .then((res) => {
          this.reportData = res.data;
          this.previewReport(this.reportData);
        })
        .catch(() => { });
    },

    innerPass(obj) {
      ReportVerifyPass(obj)
        .then((res) => {
          this.$emit("passOrNoPassEmit");
        })
        .catch();
    },
    innerReject(obj) {
      ReportVerifyReject(obj)
        .then((res) => {
          this.$emit("passOrNoPassEmit");
        })
        .catch();
    },
    innerWithdraw(obj) {
      obj.auditStatus = 60;
      ReportVerifyReject(obj)
        .then((res) => {
          this.$emit("passOrNoPassEmit");
        })
        .catch();
    },

    // 預覽報告
    previewReport(row) {
      this.filepreview.urlList = row.urlList;
      // 上传的报告
      if (row.reportUrl !== null && row.reportUrl !== "") {
        this.filepreview.fileName = row.reportFileName;
        this.filepreview.url = row.reportUrl;
        this.filepreview.storageFileName = row.reportFileName;
        this.filepreview.type = "img";
        this.previewFileShow = true;
      } else {
        this.reportHtml = row.reportFile;
        this.previewDialogVisible = true;
      }
    },
  },
};
</script>
